//
//  LSZReleasePrayerAndWitnessVC.m
//  JKFuYinProject
//
//  Created by 九酷 on 2017/12/21.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LSZReleasePrayerAndWitnessVC.h"
#import "LDImagePicker.h"

@interface LSZReleasePrayerAndWitnessVC ()<LDImagePickerDelegate,UITextViewDelegate>

//记录输入或者选择的数据
@property(nonatomic,strong) NSString * DGStringTarget;//祷告的目标 或者见证的目标
@property(nonatomic,strong) NSString * DGClassification;//祷告的分类
@property(nonatomic,strong) NSString * DGGender;//祷告的性别
@property(nonatomic,strong) NSString * DGCall;//祷告的称呼
@property(nonatomic,strong) NSString * DGContent;//祷告的内容

@property(nonatomic,strong) NSString * filePath;
@property(nonatomic,strong) UITableView * tableViewRelease;
@property(nonatomic,strong) UIView * viewTop;



//新祷告见证的
@property(nonatomic,assign) NSInteger numberPhoto;
@property(nonatomic,strong) NSMutableArray * mutArrayImageView;//装图片的数组
@property(nonatomic,strong) NSMutableArray * mutArrayImageString;//装图片地址的数组
@end

@implementation LSZReleasePrayerAndWitnessVC
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSIndexPath *indexPathA = [NSIndexPath indexPathForRow:4 inSection:0]; //刷新第0段第2行
    [self.tableViewRelease reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPathA,nil] withRowAnimation:UITableViewRowAnimationNone];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"发布";
    self.view.backgroundColor = [UIColor whiteColor];
    self.numberPhoto = 0;
    self.mutArrayImageView = [[NSMutableArray alloc]init];
    self.mutArrayImageString = [[NSMutableArray alloc]init];

    [self addTwoButChoose];
    [self setupUI];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ClickUploadPictures:) name:@"ClickUploadPictures" object:nil];//删除图片

    [self.tableViewRelease registerClass:[LSZUploadPicturesTableViewCell class] forCellReuseIdentifier:@"LSZUploadPicturesTableViewCell"];
    [self.tableViewRelease registerClass:[LSZAddMusicTableViewCell class] forCellReuseIdentifier:@"LSZAddMusicTableViewCell"];
    [self.tableViewRelease registerClass:[LSZInputTableViewCell class] forCellReuseIdentifier:@"LSZInputTableViewCell"];
}
#pragma mark - 删除的是那个图片
-(void)ClickUploadPictures:(NSNotification *)notification
{
    NSDictionary * dic = (NSDictionary *)notification.userInfo;
    int number = [dic[@"number"] intValue];//删的是第几个
    [self.mutArrayImageView removeObjectAtIndex:number];
    [self.mutArrayImageString removeObjectAtIndex:number];
    self.numberPhoto = self.numberPhoto - 1;
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];
    [self.tableViewRelease reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
}

#pragma mark - 布局
-(void)setupUI
{
    self.DGStringTarget = [[NSString alloc]initWithFormat:@"亲人"];
    self.DGClassification = [[NSString alloc]initWithFormat:@"爱情|工作|家庭"];
    self.DGGender = [[NSString alloc]initWithFormat:@"女"];
    self.DGCall = [[NSString alloc]initWithFormat:@""];

    self.tableViewRelease = [[UITableView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.viewTop.frame), ScreenWidth, ScreenHeight-CGRectGetMaxY(self.viewTop.frame)) style:UITableViewStylePlain];
    self.tableViewRelease.delegate = self;
    self.tableViewRelease.dataSource = self;
    //添加以下代码关闭估算行高
    self.tableViewRelease.estimatedRowHeight = 0;
    self.tableViewRelease.estimatedSectionHeaderHeight = 0;
    self.tableViewRelease.estimatedSectionFooterHeight = 0;
    self.tableViewRelease.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20);
    self.tableViewRelease.separatorColor = divider;
    [self.view addSubview:self.tableViewRelease];

    [self.tableViewRelease registerClass:[LSZPostedTableViewCell class] forCellReuseIdentifier:@"LSZPostedTableViewCell"];
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 40, 40);
    [rightBtn setTitle:@"完成" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = FONT_16;
    [rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 3) {
        if(self.numberPhoto/3 == 3){
            return (self.numberPhoto/3) * ((ScreenWidth-40)/3+20);
        }else{
            return (self.numberPhoto/3+1) * ((ScreenWidth-40)/3+20);
        }
    }else if (indexPath.row == 4){
        return 80;
    }else if (indexPath.row == 2){
        return 150;
    }
    else{
        if (ScreenWidth == 320) {
            //5
            return 45;
        }else if(ScreenWidth == 375){
            // 6 7
            return 50;
        }else {
            //plus
            return 58;
        }
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row < 2) {
        return [self OneSectionTableView:tableView cellForRowAtIndexPath:indexPath];
    }else if (indexPath.row == 2){
        LSZInputTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LSZInputTableViewCell" forIndexPath:indexPath];
        cell.textViewInput.delegate = self;
        cell.textViewInput.text = @"请输入你要发布的内容!";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
        return cell;
    }
    else if (indexPath.row == 3){
        LSZUploadPicturesTableViewCell * cell = [[LSZUploadPicturesTableViewCell alloc]initWithPhoneArray:self.numberPhoto :self.mutArrayImageView];
        [cell.imageViewPicture tapGesture:^(UIGestureRecognizer *ges) {
            if (cell.imageViewPicture.tag == self.numberPhoto+1) {
                [self ModifyThePicture];
            }
        }];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else {
        LSZAddMusicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZAddMusicTableViewCell" forIndexPath:indexPath];
        if(![(NullStringjudgment(self.songName)) isEqualToString:@""]){
            cell.labelTitle.text = self.songName;
            if ([self.type isEqualToString:@"5"]) {
                CGRect rect = cell.labelTitle.frame;
                rect.origin.y = rect.origin.y+(cell.labelTitle.frame.size.height)/2;
                cell.labelTitle.frame = rect;
            }
        }
        if(![(NullStringjudgment(self.authorOrAlbum)) isEqualToString:@""]){
            cell.labelAuthor.text = self.authorOrAlbum;
        }
        if(![(NullStringjudgment(self.cover_img)) isEqualToString:@""]){
            [cell.imageViewIcon sd_setImageWithURL:[NSURL URLWithString:self.cover_img] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        }
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
- (UITableViewCell *)OneSectionTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZPostedTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZPostedTableViewCell" forIndexPath:indexPath];
    if(self.choosePosted == 1){
        if (indexPath.row == 0) {
            cell.labelClass.text = @"祷告目标";
            cell.labelContent.text = [NSString stringWithFormat:@"%@",self.DGStringTarget];
            cell.labelContent.hidden = NO;
            cell.textFieldName.hidden = YES;
            cell.textViewControl.hidden = YES;
        }else if (indexPath.row == 1){
            cell.labelClass.text = @"祷告分类";
            cell.labelContent.text = [NSString stringWithFormat:@"%@",self.DGClassification];
            cell.labelContent.hidden = NO;
            cell.textFieldName.hidden = YES;
            cell.textViewControl.hidden = YES;
        }

    }else{
        if (indexPath.row == 0) {
            cell.labelClass.text = @"见证标题";
            cell.labelContent.hidden = YES;
            cell.textFieldName.hidden = NO;
            cell.textViewControl.hidden = YES;
            if ([self.DGStringTarget isEqualToString:@""]) {
                cell.textFieldName.placeholder = @"请输入标题";
            }else{
                cell.labelContent.text = [NSString stringWithFormat:@"%@",self.DGStringTarget];
            }
        }else if (indexPath.row == 1){
            cell.labelClass.text = @"见证分类";
            cell.labelContent.text = [NSString stringWithFormat:@"%@",self.DGClassification];
            cell.labelContent.hidden = NO;
            cell.textFieldName.hidden = YES;
            cell.textViewControl.hidden = YES;
        }

    }
    if(indexPath.row < 3){
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.selectionStyle = UITableViewCellStyleDefault;
    return cell;
}
#pragma mark - 上传图片
-(void)ModifyThePicture
{
    __weak typeof(self) weakSelf = self;
    UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *showAllInfoAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [weakSelf initWithPhoneFromThePhotoAlbum];
    }];
    UIAlertAction *pickAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [weakSelf initWithPhoneTakingpictures];
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    [actionSheetController addAction:cancelAction];
    [actionSheetController addAction:pickAction];
    [actionSheetController addAction:showAllInfoAction];
    [weakSelf presentViewController:actionSheetController animated:YES completion:nil];
}
#pragma mark - 拍照
-(void)initWithPhoneTakingpictures
{
    NSUInteger sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    // 判断是否支持相机
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        //来源:相机
        sourceType = UIImagePickerControllerSourceTypeCamera;
        NSString * mediaType = AVMediaTypeVideo;
        AVAuthorizationStatus  authorizationStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
        if (authorizationStatus == AVAuthorizationStatusRestricted|| authorizationStatus == AVAuthorizationStatusDenied) {
            [self initWithtring:@"摄像头访问受限,请打开摄像头允许拍摄!"];
            return;
        }
    }
    else {
        [self initWithtring:@"此设备没有摄像功能!"];
        return;
    }
    // 跳转到相机或相册页面
    LDImagePicker *imagePicker = [LDImagePicker sharedInstance];
    imagePicker.delegate = self;
    //设置宽高比scale来设置剪切框大小，剪切框宽度固定为屏幕宽度
    [imagePicker showImagePickerWithType:0   InViewController:self Scale:1];
}
#pragma mark - 从相册里面查找
-(void)initWithPhoneFromThePhotoAlbum
{
    NSUInteger sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    // 判断是否支持相机
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        //来源:相册//来自图库
        sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
        if (author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied){
            //无权限
            [self initWithtring:@"照片访问受限,请允许app访问你的照片!"];
            return;
        }
    }
    else {
        //来自相册
        sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
        if (author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied){
            //无权限
            [self initWithtring:@"照片访问受限,请允许app访问你的照片!"];
            return;
        }
    }
    // 跳转到相机或相册页面
    // 跳转到相机或相册页面
    LDImagePicker *imagePicker = [LDImagePicker sharedInstance];
    imagePicker.delegate = self;
    //设置宽高比scale来设置剪切框大小，剪切框宽度固定为屏幕宽度
    [imagePicker showImagePickerWithType:1   InViewController:self Scale:1];
}
- (void)imagePicker:(LDImagePicker *)imagePicker didFinished:(UIImage *)editedImage{
    __weak typeof(self) weakSelf = self;
    LSZUploadPicturesTableViewCell * cell = (LSZUploadPicturesTableViewCell *)[weakSelf.tableViewRelease cellForRowAtIndexPath:[NSIndexPath indexPathForRow:3  inSection:0]];
    cell.imageViewPicture.image = editedImage;
    [self.mutArrayImageView addObject:editedImage];
    UIImage *imagestr = editedImage;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@""]];   // 保存文件的名称
    [self.mutArrayImageString addObject:filePath];
    //    BOOL result = [UIImagePNGRepresentation(imagestr)writeToFile: filePath    atomically:YES]; // 保存成功会返回YES
    self.numberPhoto = self.numberPhoto + 1;
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];
    [self.tableViewRelease reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];

}
-(void)keyboardWhereabouts
{
    [self.view endEditing:YES];
}
- (void)imagePickerDidCancel:(LDImagePicker *)imagePicker{

}
-(BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizershouldReceiveTouch:(UITouch *)touch
{
    if([NSStringFromClass([touch.view class])isEqualToString:@"UITableViewCellContentView"]) {
        return NO;
    }
    return YES;
}
#pragma mark - 单元格的点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 4){
        LSZAudioRViewController * vc = [[LSZAudioRViewController alloc]init];
        vc.fromWhere = @"1";
        [self.navigationController pushViewController:vc animated:YES];
    }else if(self.choosePosted == 1){
        if (indexPath.row == 0) {
            NSArray *  arrayMonth = @[@"自己",@"亲人",@"朋友",@"他人",@"教会",@"国家"];
            [self chooseControl :arrayMonth  :indexPath.row];
        }
        if (indexPath.row == 1){
            NSArray *  arrayMonth = @[@"信仰|灵命",@"家庭|婚姻|爱情",@"健康|医治",@"教会|团契",@"事业|工作",@"学业|考试",@"国家|社会",@"国度|事工",@"其他"];
            [self chooseControl :arrayMonth  :indexPath.row];
        }
        if(indexPath.row == 2){
            LSZPrayerWitnessVC * VC = [[LSZPrayerWitnessVC alloc]init];
            VC.titleString = @"祷告内容";
            [self.navigationController pushViewController:VC animated:YES];
        }
    }
    else{
        if (indexPath.row == 1){
            NSArray *  arrayMonth = @[@"信仰|灵命",@"家庭|婚姻|爱情",@"健康|医治",@"教会|团契",@"事业|工作",@"学业|考试",@"国家|社会",@"国度|事工",@"其他"];
            [self chooseControl :arrayMonth :indexPath.row];
        }
        if(indexPath.row == 2){
            NSLog(@"内容跳到下一个界面");
            LSZPrayerWitnessVC * VC = [[LSZPrayerWitnessVC alloc]init];
            VC.titleString = @"见证内容";
            [self.navigationController pushViewController:VC animated:YES];
          }
    }
}
//记录输入或者选择的数据
-(void)chooseControl :(NSArray *)array :(NSInteger)numberRow
{
    [self.view endEditing:YES];
    DLPickerView *pickerView = [[DLPickerView alloc] initWithDataSource:array
                                                       withSelectedItem:nil
                                                      withSelectedBlock:^(id selectedItem)
                                {
                                if(numberRow == 0){
                                    self.DGStringTarget = [NSString stringWithFormat:@"%@",selectedItem];
                                }
                                if (numberRow == 1){
                                    self.DGClassification = [NSString stringWithFormat:@"%@",selectedItem];
                                }
                                if (numberRow == 2){
                                    self.DGGender = [NSString stringWithFormat:@"%@",selectedItem];
                                }
                                [self.tableViewRelease reloadData];
                                }];
    [pickerView show];
}
#pragma mark - 取消按钮
-(void)leftBtnAction
{
    NSNotification *notification =[NSNotification notificationWithName:@"fbdgjz" object:nil userInfo:nil];
    [[NSNotificationCenter defaultCenter] postNotification:notification];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"fbdgjz" object:nil];
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - 完成按钮 数据先暂时隐藏
-(void)rightBtnAction
{
    NSString * topicString = [[NSString alloc]init];
    NSString * toname = [[NSString alloc]init];
    if(self.choosePosted == 1){
        toname = @"祷告";
    }
    else{
        toname = @"见证";
        LSZPostedTableViewCell * cellThree = (LSZPostedTableViewCell *)[self.tableViewRelease cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0  inSection:0]];
        self.DGStringTarget = [NSString stringWithFormat:@"%@",cellThree.textFieldName.text];
    }
    NSString * xingBieChange = [[NSString alloc]init];
    if([self.DGGender isEqualToString:@"男"]){
        xingBieChange = [NSString stringWithFormat:@"0"];
    }else{
        xingBieChange = [NSString stringWithFormat:@"1"];
    }
    if ([self.DGStringTarget isEqualToString:@""]||self.DGStringTarget.length == 0){
        [self initWithtring:@"请填写目标或者标题!"];
        return;
    }
    if ([self.DGClassification isEqualToString:@""]||self.DGClassification.length == 0){
        [self initWithtring:@"请选择分类!"];
        return;
    }
    if ([self.DGContent isEqualToString:@""]||self.DGContent.length == 0){
        [self initWithtring:@"请填写内容!"];
        return;
    }
    NSString * string = [[NSString alloc]init];
    for (int i = 0; i <self.mutArrayImageString.count; i++) {
        if (i == 0) {
            string = [NSString stringWithFormat:@"%@",self.mutArrayImageString[i]];
        }else{
            string = [NSString stringWithFormat:@"%@,%@",string,self.mutArrayImageString[i]];
        }
    }
    topicString = [[NSString alloc]initWithFormat:@"为%@关于%@的%@",self.DGStringTarget,self.DGClassification,toname];
    //上传图片
    [LSZRequestResolutionDic uploadFilesOfVariousTypes:self.mutArrayImageView filePath:self.mutArrayImageString :^(BOOL isOK, NSString * string, LSZFileUploadGenericManager * manager) {
        if(isOK == YES){
            NSString * type = NullStringjudgment(NSStr(self.type));
            NSString * resource = NullStringjudgment(NSStr(self.resource));
            [LSZRequestData releaseTheDynamic:self.kind type:type resource:resource  title:topicString content:self.DGContent theme:@"" images:manager.idString :^(BOOL isOk, NSString * Str, NSDictionary * dicTion) {
                [self initWithtring:Str];
                if (isOK == YES) {
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        // 刷新表格  和结束刷新
                        if ([Str rangeOfString:@"成功"].location != NSNotFound) {
                            [self.navigationController popViewControllerAnimated:YES];
                        }
                    });
                }
            }];
        }else{
            [self initWithtring:string];
        }
    }];
}
-(void)clickButChoose:(UIButton *)but
{
    if(self.choosePosted == but.tag){
        return;
    }
    self.choosePosted = but.tag;
    UIButton * butOne = [self.view viewWithTag:1];
    UIButton * butTwo = [self.view viewWithTag:2];
    if (but.tag ==1) {
        [butOne setTitleColor:RGBColor(228, 82, 77)  forState:UIControlStateNormal];
        [butTwo setTitleColor:RGBColor(153, 153, 153)  forState:UIControlStateNormal];
        self.DGStringTarget = [[NSString alloc]initWithFormat:@"亲人"];
    }else{
        [butTwo setTitleColor:RGBColor(228, 82, 77)  forState:UIControlStateNormal];
        [butOne setTitleColor:RGBColor(153, 153, 153)  forState:UIControlStateNormal];
        self.DGStringTarget = [[NSString alloc]initWithFormat:@""];
    }
    [self.tableViewRelease reloadData];
}
-(void)addTwoButChoose
{
    self.viewTop = [[UIView alloc]init];

    if (ScreenWidth == 320) {
        //5
        self.viewTop.frame = CGRectMake(0,NAVIGATION_BAR_HEIGHT, ScreenWidth, 45);
    }else if(ScreenWidth == 375){
        // 6 7
        self.viewTop.frame = CGRectMake(0,NAVIGATION_BAR_HEIGHT, ScreenWidth, 50);
    }else {
        //plus
        self.viewTop.frame = CGRectMake(0,NAVIGATION_BAR_HEIGHT, ScreenWidth, 58);
    }
    [self.view addSubview:self.viewTop];
    NSArray * array = @[@"发布祷告",@"发布见证"];
    for (int i = 0; i<2; i++) {
        UIButton * butchoose = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2*i, 0, ScreenWidth/2, self.viewTop.frame.size.height)];
        [butchoose setTitle:[NSString stringWithFormat:@"%@",array[i]] forState:UIControlStateNormal];
        if (ScreenWidth == 320) {
            //5
            butchoose.titleLabel.font = FONT_(13.5);
        }else if(ScreenWidth == 375){
            // 6 7
            butchoose.titleLabel.font = FONT_(14);
        }else {
            //plus
            butchoose.titleLabel.font = FONT_(14.5);
        }
        butchoose.tag = i+1;
        [butchoose addTarget:self action:@selector(clickButChoose:) forControlEvents:UIControlEventTouchUpInside];
        [self.viewTop addSubview:butchoose];
        if (i == 0) {
             [butchoose setTitleColor:redUIColor  forState:UIControlStateNormal];
        }else{
            [butchoose setTitleColor:lightColor  forState:UIControlStateNormal];
            if (ScreenWidth == 320) {
                //5
                [LSZSpecialPackaging addThreadWithOtherRGB:self.viewTop A:(ScreenWidth-1)/2 B:16 C:1 D:45-16*2 R:241 G:241 BB:241];
            }else if(ScreenWidth == 375){
                // 6 7
                [LSZSpecialPackaging addThreadWithOtherRGB:self.viewTop A:(ScreenWidth-1)/2 B:17 C:1 D:50-17*2 R:241 G:241 BB:241];
            }else {
                //plus
                [LSZSpecialPackaging addThreadWithOtherRGB:self.viewTop A:(ScreenWidth-1)/2 B:18 C:1 D:58-18*2 R:241 G:241 BB:241];
            }
            [LSZSpecialPackaging addThreadWithOtherRGB:self.viewTop A:0 B:self.viewTop.frame.size.height-1 C:self.viewTop.frame.size.width D:1 R:241 G:241 BB:241];
        }
    }
}
#pragma mark - UITextViewDelegate
- (void)textViewDidEndEditing:(UITextView *)textView
{
    if(textView.text.length < 1){
        textView.textColor = [UIColor grayColor];
        textView.text = @"请输入你要发布的内容!";
    }
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:@"请输入你要发布的内容!"]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}
//这个函数的最后一个参数text代表你每次输入的的那个字，所以：
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    NSString * strLong = [textView.text stringByReplacingCharactersInRange:range withString:text];
    self.DGContent = strLong;
    NSLog(@"11111111>>>>>>%@",strLong);
    if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车，即按下return
        //在这里做你响应return键的代码
        [self.view endEditing:YES];
        return NO; //这里返回NO，就代表return键值失效，即页面上按下return，不会出现换行，如果为yes，则输入页面会换行
    }
    return YES;
}
@end
